<template>
  <div class="login">
    <h2>登录</h2>
    <select v-model="selectedRole">
      <option value="1">管理员</option>
      <option value="2">用户</option>
      <option value="3">商家</option>
    </select>
    <button @click="login">登录</button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { userApi } from '@/api/user'



const router = useRouter()
const userStore = useUserStore()
const selectedRole = ref('2')

// 登录
async function login() {
  try {
    const res = await userApi.login({
      userName: 'test',
      password: '123456'
    })
    console.log('登录成功：', res)
    userStore.login(Number(selectedRole.value))
    router.push('/')
  } catch (error) {
    console.error('登录失败：', error)
  }
}

</script> 